
window.onload = function(){
//	var oInput = document.querySelector('.s-in');
//	var oSearch = document.querySelector('.search');
//	var oSimg = oSearch.querySelector('img');
	var oX = document.querySelector('.x');
	var oRSC = document.querySelector('.rightSideQRCode');
	oX.onclick = function(){
		oRSC.style.display='none';
	};
//	oSimg.onclick=function(){
//		oInput.style.display='block';
//	};
//	oSearch.onmouseleave = function(){
//		oInput.style.display='none';
//	};
	$("#s-img").click(function(){
		if($("#s-in").css("left")=="230px"){
			$("#s-in").animate({"left":"0px"},1000)
		}else if($("#s-in input").val()==""){
			$("#s-in").animate({"left":"230px"},1000)
		}else{
			var searchText = $("#s-in input").val();
			console.log(searchText)
			location.href = "search.html?search_text="+searchText;
			
			
		};
	});
	

	
	
//	var oShangjiantou = document.querySelector('.shangjiantou');
//	oShangjiantou.onclick=function(){
//				scroll(0,0);}
	
	$(window).scroll(function(){
		if($(this).scrollTop() >= 200){
			$('.shangjiantou').css("display","block");
		}else{
			$('.shangjiantou').css("display","none");
		};
		
	});
	$('.shangjiantou').click(function(){
		$("html,body").animate({scrollTop:0},800);
	});
		var api = 'http://h6.duchengjiu.top/shop/';
	
	//请求分类
	(function(){
		//获取到要放入的容器
		var classifyC = document.getElementById('classify-content');
		//console.log(classifyC);
		$.get(api + 'api_cat.php', {}, function(result){
			var data = result.data;
			//console.log(data);
			//把分类遍历出来
			var strA = '';
			for(var i = 0; i < data.length; i++){
				strA += '<a href="classify.html?cart_id='+ data[i].cat_id+'">' + data[i].cat_name+ '</a>';
			};
			//console.log(strA);
			classifyC.innerHTML = strA;
		});
			
	})();
	
	(function(){
		var localName = localStorage.getItem('username');
		var oLog = document.getElementById('log');
		var oReg = document.getElementById('reg');
		var oWel = document.getElementById('wel');
		var oQuit = document.getElementById('quit');
		var oCart = document.getElementById('cart');
		
		if(localName){
			oLog.style.display='none';
			oReg.style.display='none';
			oWel.style.display='block';
			oWel.innerHTML+=localName;
			oQuit.style.display='block';
		}else{
			oLog.style.display='block';
			oReg.style.display='block';
			oWel.style.display='none';
			oQuit.style.display='none';
		};
		
		oQuit.onclick = function(){
			localStorage.removeItem('token');
			localName=localStorage.removeItem('username');
			oLog.style.display='block';
			oReg.style.display='block';
			oWel.style.display='none';
			oQuit.style.display='none';
		};
		
		oCart.onclick = function(){
			if(localName){
				location.href='shop.html';
			}else{
				alert('您还未登录,请先登录!');
				location.href='denglu-2.html';
			}
		};
	})();
	
}
